package com.ruoyi.member.service.impl;

import com.ruoyi.member.domain.MemberLike;
import com.ruoyi.member.mapper.MemberLikeMapper;
import com.ruoyi.member.service.IMemberLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

/**
 * 会员点赞Service业务层处理
 *
 * @author ruoyi
 * @date 2025-10-24
 */
@Service
public class MemberLikeServiceImpl implements IMemberLikeService {

    @Autowired
    private MemberLikeMapper memberLikeMapper;

    /**
     * 查询会员点赞列表
     *
     * @param memberLike 会员点赞
     * @return 会员点赞集合
     */
    @Override
    public List<MemberLike> selectMemberLikeList(MemberLike memberLike) {
        return memberLikeMapper.selectMemberLikeList(memberLike);
    }

    /**
     * 新增会员点赞
     *
     * @param memberLike 会员点赞
     * @return 结果
     */
    @Override
    public int insertMemberLike(MemberLike memberLike) {
        memberLike.setCreateTime(new Date());
        return memberLikeMapper.insertMemberLike(memberLike);
    }

    /**
     * 取消点赞短视频
     *
     * @param userId 用户ID
     * @param shortId 短视频ID
     * @return 结果
     */
    @Override
    public int cancelLike(Long userId, Integer shortId) {
        return memberLikeMapper.deleteMemberLikeByMemberAndShort(userId, shortId);
    }

    /**
     * 检查是否已点赞短视频
     *
     * @param userId 用户ID
     * @param shortId 短视频ID
     * @return 是否已点赞
     */
    @Override
    public boolean checkLiked(Long userId, Integer shortId) {
        int count = memberLikeMapper.checkLikeExists(userId, shortId);
        return count > 0;
    }
}
